﻿using System;
using System.Collections.Generic;
using System.Text;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Smile.Mvvm.Service
{
    /// <summary>Service which manage page navigation.</summary>
    public class NavService : INavigationService
    {
        // @Public
        public void Navigate<TPage>()
        {
            var frame = Window.Current.Content as Frame;
            if (frame == null)
            {
                return;
            }

            frame.Navigate(typeof(TPage));
        }

        public void GoBack()
        {
            // Get application frame.
            var frame = Window.Current.Content as Frame;
            if (frame == null)
            {
                return;
            }

            // Go back action.
            if (frame.CanGoBack)
            {
                frame.GoBack();
            }
        }

        public void Reset()
        {
            // Get application frame.
            var frame = Window.Current.Content as Frame;
            if (frame == null)
            {
                return;
            }

            // Reset action
            while (frame.CanGoBack)
            {
                frame.GoBack();
            }
        }
    }
}
